namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;

    [XmlRoot("th")]
    public class TableHeaderCell : Cell, IXmlSerializable
    {
        public string Scope
        {
            get;
            set;
        }

        public override IElement Deserialize(string name, string type, string xml)
        {
            IElement result = null;

            if (null == type && "th".Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                result = xml.Deserialize<TableHeaderCell>();
            }

            return result;
        }

        public override void ReadXml(XmlReader reader)
        {
            string value = reader.GetAttribute("scope");
            if (!string.IsNullOrEmpty(value))
            {
                this.Scope = value;
            }

            base.ReadXml(reader);
        }

        public override void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Scope))
            {
                writer.WriteAttributeString("scope", this.Scope);
            }

            base.WriteXml(writer);
        }
    }
}